/*******************************************************************************
 * Copyright (c) 2010 Gary Yund {OTHER COPYRIGHT OWNERS}.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Gary Yund - initial API and implementation and/or initial documentation
 *******************************************************************************/

#import <Foundation/Foundation.h>

/**
 BB_LOG_NONE       = Display no errors
 BB_LOG_DEBUG      = Log/Display general debugging messages
 BB_LOG_ERROR      = Log/Display error conditions
 
 BB_LOG_LOGIC      = Log/Display logical decisions or choices
 BB_LOG_EVENT      = Log/Display events, such as button clicks or mode change
 BB_LOG_COREDATA   = Log/Display information relating to core data operations
 
 BB_LOG_LIFECYCLE  = Log/Display lifecycle, such as object/thread create/destroy
 

 */
typedef enum BB_LogLevel_e {
    
    // COMMON LOG LEVELS
    BB_LOG_NONE         = 0,
    BB_LOG_DEBUG        = 0x0001,
    BB_LOG_ERROR        = 0x0002,
    
    // PROGRAM FLOW LOGGING
    BB_LOG_LOGIC        = 0x0010,
    BB_LOG_EVENT        = 0x0020, 
    BB_LOG_COREDATA     = 0x0040,
    
    BB_LOG_LIFECYCLE    = 0x0100,

    // NOT A LOG LEVEL (USED FOR FILTERING)
    BB_LOG_ANY          = 0xFFFF
} BB_LogLevel_t;

@interface BB_Logger : NSObject {
    BB_LogLevel_t logLevel;
}

/**
 Returns a reference to the singleton BB_Logger. Implemented by the macro
 SYNTHESIZE_SINGLETON_FOR_CLASS
*/
+(BB_Logger*) sharedBB_Logger;

/**
 Assigns which log levels should be logged and displayed
*/
-(void)setLogLevel:(BB_LogLevel_t)level;

/**
 Logs a string at a given level
*/
-(void)log:(NSString*)string atLevel:(BB_LogLevel_t)level;

@property (readonly) BB_LogLevel_t logLevel;

@end

#ifdef USING_BB_LOGGING

/**
    Assigns which log levels should be logged and displayed
*/
#define BB_LOGLEVEL(level) [[BB_Logger sharedBB_Logger] setLogLevel:level];

/**
 Logs a string at a given level
*/
#define BB_LOG(level, fmt, ...) [[BB_Logger sharedBB_Logger] log:[NSString stringWithFormat:@"%s [Line %d] %@", __PRETTY_FUNCTION__, __LINE__, [NSString stringWithFormat:fmt, ##__VA_ARGS__]] atLevel:level]; 


//NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

#else
#define BB_LOGLEVEL(...)
#define BB_LOG(...)
#endif // END #ifdef USING_BB_LOGGING


